<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .count{
            display: inline-block;
            border-radius: 50%;
            width: 150px;
            height: 150px;
            background: pink;
            line-height: 150px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div id="app">
        <v-count1 :count="count" @updatecount="updatecount"></v-count1>
        <v-count2 :count="count" @updatecount="updatecount"></v-count2>
    </div>
</body>
<script src="../js/vue.js"></script>
<script>


    var count1 = {
        name:"v-count1",
        props:["count"],
        template:`<span class="count" @click="addFn">{{count}}</span>`,
        data(){
            return {
                name:"count1"
            }
        },
        methods:{
            addFn(){
                //通知父组件自己修改数据
                this.$emit("updatecount",this.$options.name)
            }
        }
    }
    var count2 = {
        name:"v-count2",
        props:["count"],
        template:`<span class="count" @click="addFn">{{count}}</span>`,
        data(){
            return {
                name:"count2"
            }
        },
        methods:{
            addFn(){
                //通知父组件自己修改数据
                this.$emit("updatecount",this.$options.name)
            }
        }
    }


    Vue.config.productionTip = false;
    var vm = new Vue({
        el:"#app",
        data:{
            count:0
        },
        components:{
            "v-count1":count1,
            "v-count2":count2
        },
        methods:{
            updatecount(flag){
                //区分开到底谁在修改??
                if(flag === "v-count1"){
                    this.count++
                }
            }
        }
    })
</script>
</html>